﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public delegate void OnUploadCompleted(string selectedFile);
public partial class Members_Upload : System.Web.UI.UserControl
{
    private string strUploadFolderPath = null;

    public bool Enabled
    {
        get { return !btnUpload.Disabled; }
        set { btnUpload.Disabled = !value; }
    }

    public string UploadFolderPath
    {
        get { return strUploadFolderPath; }
        set { strUploadFolderPath = value; }
    }

    public event OnUploadCompleted OnUploadCompleted;

    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(Page.GetType(), this.ClientID + "_openUpload",
            "<script type=text/javascript> function " + this.ClientID + "_openUpload()" +
            "{ window.open('Uploader.aspx?OpenerID=" + this.ClientID +
            "&Folder=" + this.UploadFolderPath + "', 'Upload','width=700,height=520') } </script>");

        btnUpload.Attributes.Add("onclick", this.ClientID + "_openUpload()");
    }

    protected void btnPostback_Click(object sender, EventArgs e)
    {
        OnUploadCompleted((string)Session["SelectedFile"]);
        //Response.Write(Session["SelectedFile"].ToString());
    }

    protected string GetPostBackScript()
    {
        PostBackOptions opt = new PostBackOptions(btnPostback);
        Page.ClientScript.RegisterForEventValidation(opt);
        return Page.ClientScript.GetPostBackEventReference(opt);
    }
}
